package service

import (
	"github.com/astaxie/beego/orm"
	"net/url"
	"xianzhi/models"
)

// 获取站点配置信息
func GetSiteConfigInfo(p map[string]interface{}) *models.SiteConfig {
	o := orm.NewOrm()
	siteConfig := &models.SiteConfig{}
	qs := o.QueryTable("SiteConfig")
	if _, ok := p["relation"]; ok && p["relation"].(bool) {
		qs = qs.RelatedSel()
	}
	if _, ok := p["id"]; ok {
		qs = qs.Filter("id", p["id"])
	}
	qs.One(siteConfig)
	return siteConfig
}

// 修改站点配置信息
func EditSiteConfig(input url.Values) (int64, error) {
	o := orm.NewOrm()
	p := orm.Params{}
	for k, v := range input {
		if k == "id" || k == "_xsrf" {
			continue
		}
		p[k] = v[0]
	}
	return o.QueryTable("SiteConfig").Filter("id", input["id"][0]).Update(p)
}